from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone

class Paper(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=255)
    author = models.CharField(max_length=255)
    publication = models.CharField(max_length=255)
    year = models.IntegerField()
    abstract = models.TextField()
    file = models.FileField(upload_to='papers/')
    content = models.TextField(blank=True, null=True)
    upload_time = models.DateTimeField(default=timezone.now)
    
    def __str__(self):
        return self.title

class Thesis(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=255)
    structure = models.TextField()
    content = models.TextField()
    create_time = models.DateTimeField(default=timezone.now)
    update_time = models.DateTimeField(auto_now=True)
    
    def __str__(self):
        return self.title

class Reference(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    thesis = models.ForeignKey(Thesis, on_delete=models.CASCADE, blank=True, null=True)
    title = models.CharField(max_length=255)
    author = models.CharField(max_length=255)
    publication = models.CharField(max_length=255)
    year = models.IntegerField()
    format = models.TextField(blank=True, null=True)
    create_time = models.DateTimeField(default=timezone.now)
    
    def __str__(self):
        return self.title